// 定义发请求的js
// 第一步：定义接口
import request from '@/utils/request'
// import store from "@/store";
export function getArticleList (params) {
  return request({
    method: 'GET',
    url: '/v1_0/articles',
    params
  })
}

export function getAllChannels () {
  return request({
    method: 'GET',
    url: '/v1_0/channels'
  })
}

// 定义获取频道的接口
export const getArticleById = articleId => {
  return request({
    method: 'GET',
    url: '/v1_0/articles/' + articleId
  })
  // return new Promise((resolve, reject) => {
  //   setTimeout(() => {
  //   }, 500)
  // })
}

export const addCollect = target => {
  return request({
    method: 'POST',
    url: '/v1_0/article/collections',
    data: {
      target
    }
  })
}

export const deleteCollect = target => {
  return request({
    method: 'DELETE',
    url: '/v1_0/article/collections',
    data: {
      target
    }
  })
}

/**
 * 点赞
 */
export const addLike = articleId => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target: articleId
    }
  })
}

/**
 * 取消点赞
 */
export const deleteLike = articleId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/likings/${articleId}`
  })
}